#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
  pid_t ret = fork();//其返回值是pid类型的
  if(ret > 0)//父进程返回的是子进程ID
  {
    while(1){
      printf("I am an parent! pid : %d\n", getpid());
      sleep(1);
    }
  }
  else if(ret == 0){//子进程fork返回值是0
    int count = 0;

    while(count < 5){
      printf("I am a child! pid : %d, ppid : %d\n", getpid(), getppid());
      sleep(1);
      count++;
    }
  }
  else{
    printf("fork error\n");
  }

  return 0;
}
